//
//  NewFocusWordCell.m
//  suRead
//
//  Created by lidi on 2018/6/1.
//  Copyright © 2018年 bao. All rights reserved.
//

#import "NewFocusWordCell.h"
#import "SDCycleScrollView.h"
#import "M_SpecialNews.h"
#import "M_News.h"
#import "LMJScrollTextView2.h"
#import "Masonry.h"

@interface NewFocusWordCell()<LMJScrollTextView2Delegate>
@property (weak, nonatomic) IBOutlet LMJScrollTextView2 *cycleScrollView;
@end

@implementation NewFocusWordCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    // Initialization code
    UIView *bottomLine = [UIView new];
    bottomLine.backgroundColor = [UIColor colorWithRed:0xee / 255.0f green:0xee / 255.0f blue:0xee / 255.0f alpha:1];
    [self.contentView addSubview:bottomLine];
    [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomLine.superview).offset(15.0);
        make.right.equalTo(bottomLine.superview).offset(-15.0);
        make.bottom.equalTo(bottomLine.superview);
        make.height.equalTo(@.5f);
    }];
}

- (void)setNewsDatas:(NSArray *)newsDatas
{
    _newsDatas = newsDatas;
    
    NSInteger focusCount = [newsDatas count];
    if (!focusCount) {
        return;
    }
    
    NSMutableArray *focusNews_ = [NSMutableArray array];
    
    for (int i = 0; i < [_newsDatas count]; i ++) {
        NSString *imageURL;
        if ([[_newsDatas objectAtIndex:i] isKindOfClass:[M_SpecialNews class]]) {
            M_SpecialNews *news = [_newsDatas objectAtIndex:i];
            imageURL = news.f_title;
        } else {
            M_News *news = [_newsDatas objectAtIndex:i];
            imageURL = news.f_title;
        }
        [focusNews_ addObject:imageURL];
    }
    
    self.cycleScrollView.delegate            = self;
    self.cycleScrollView.textStayTime        = 2;
    self.cycleScrollView.scrollAnimationTime = 1;
    self.cycleScrollView.textColor           = [UIColor blackColor];
    self.cycleScrollView.textFont            = [UIFont fontWithName:@"FZBIAOYSJW--GB1-0" size:15.0f];
    self.cycleScrollView.textAlignment       = NSTextAlignmentLeft;
    self.cycleScrollView.touchEnable         = YES;
    
    self.cycleScrollView.textDataArr = focusNews_;
    
    __weak typeof(self) weakSelf = self;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [weakSelf.cycleScrollView startScrollBottomToTopWithNoSpace];
    });
    
}

- (IBAction)moreAction:(id)sender {
    if (self.actionMore) {
        self.actionMore();
    }
}

#pragma mark - LMJScrollTextView2 Delegate
- (void)scrollTextView2:(LMJScrollTextView2 *)scrollTextView clickIndex:(NSInteger)index content:(NSString *)content{
    if (self.focusTapAtIndex) {
        self.focusTapAtIndex([self.newsDatas objectAtIndex:index]);
    }
}

@end
